package com.example.moblie2021606143cwj0509;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class PartActivity extends AppCompatActivity {

    private RadioGroup radioGroup;
    private RadioButton rdbtnMainYingqing;
    private RadioButton rdbtnMainQianboli;
    private RadioButton rdbtnMainLuntai;
    private RadioButton rdbtnMainDipan;
    private RadioButton rdbtnMainQianggai;
    private RadioButton rdbtnMainXugua;
    private RadioButton rdbtnMainZuoyi;
    private RadioButton rdbtnMainFangxiangpang;
    private RadioButton rdbtnMainChejia;
    private RadioButton rdbtnMainChemeng;
    private RadioButton rdbtnMainHouboli;
    private TextView tvMainTitle2;
    private Button btnPartAdd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_part);
        initView();
        btnPartAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int radBtnId=radioGroup.getCheckedRadioButtonId();
                if (radBtnId!=-1){
                            RadioButton radioButton=findViewById(radBtnId);
                            Intent intent=new Intent();
                            intent.putExtra("Part",radioButton.getText().toString());
                            setResult(RESULT_OK,intent);
                            finish();
                        }else {
                            new AlertDialog.Builder(PartActivity.this)
                                    .setMessage("请选择原材料商")
                                    .setPositiveButton("确定",null)
                                    .create()
                                    .show();
                        }

            }
        });
    }

    private void initView() {
        radioGroup = findViewById(R.id.radioGroup);
        rdbtnMainYingqing = findViewById(R.id.rdbtn_main_yingqing);
        rdbtnMainQianboli = findViewById(R.id.rdbtn_main_qianboli);
        rdbtnMainLuntai = findViewById(R.id.rdbtn_main_luntai);
        rdbtnMainDipan = findViewById(R.id.rdbtn_main_dipan);
        rdbtnMainQianggai = findViewById(R.id.rdbtn_main_qianggai);
        rdbtnMainXugua = findViewById(R.id.rdbtn_main_xugua);
        rdbtnMainZuoyi = findViewById(R.id.rdbtn_main_zuoyi);
        rdbtnMainFangxiangpang = findViewById(R.id.rdbtn_main_fangxiangpang);
        rdbtnMainChejia = findViewById(R.id.rdbtn_main_chejia);
        rdbtnMainChemeng = findViewById(R.id.rdbtn_main_chemeng);
        rdbtnMainHouboli = findViewById(R.id.rdbtn_main_houboli);
        tvMainTitle2 = findViewById(R.id.tv_main_title2);
        btnPartAdd = findViewById(R.id.btn_part_add);
    }
}


